import { createRouter, createWebHistory, RouteLocationNormalized, RouteRecordRaw } from 'vue-router';
import routes from './routes';
import HomePage from '@/pages/homePage';
import Reservation from '@/pages/reservation/Reservation.vue';

const routes: Array<RouteRecordRaw> = [
	{
		path: '/',
		name: 'Home',
		component: HomePage
	},
	{
		path: '/reservation',
		name: 'Reservation',
		component: Reservation
	},
	{
		path: '/login',
		name: 'Login',
		component: () => import('@/pages/login/index.vue') // 登录页面，需要单独创建
	}
];

const router = createRouter({
	history: createWebHistory(),
	routes
});

const setTitle = (to: RouteLocationNormalized) => {
	// 设置页面标题
	document.title = (to.meta && (to.meta.title as string)) || '特创YI';
};

// 路由拦截
router.beforeEach(to => {
	setTitle(to);
});

export default router;
